package com.jy.adscm.dealer.controller;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.jy.adscm.dealer.bean.DealerAttachment;
import com.jy.adscm.dealer.bean.DealerMembers;
import com.jy.adscm.dealer.service.DealerAttachmentService;
import com.jy.adscm.dealer.service.DealerMembersService;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.system.utils.AdscmSystemUtils;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.servlet.http.HttpServletRequest;
import javax.sound.midi.Soundbank;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-01-16
 */
@RestController
@RequestMapping("/adscm/dealer/dealerAttachment")
public class DealerAttachmentController {
    @Value("${spring.http.multipart.location}")
    private  String uploadPath;//附件上传路径
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;

    @Autowired
    com.jy.adscm.dealer.service.DealerAttachmentService dealerAttachmentService;



    @RequestMapping("update")
    public SimpleCoreResponse update( HttpServletRequest request) throws AdscmSystemException {

        boolean insert = dealerAttachmentService.insertDealerAttachment(request );
        return new SimpleCoreResponse("200","新增成功",insert);
    }
    @RequestMapping("delete/{id}")
    public SimpleCoreResponse delete(@PathVariable Integer id, HttpServletRequest request) throws AdscmSystemException{
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        List<DealerAttachment> result = dealerAttachmentService.deleteDealerMembers(id,token);
        return  new SimpleCoreResponse("200","修改成功",result);
    }


    @RequestMapping("selectByDid/{did}")
    public SimpleCoreResponse selectByDid(@PathVariable Integer did, HttpServletRequest request) throws AdscmSystemException{
        String tokenId = request.getParameter("tokenId");
        AdscmBaseUtils.getInstance().getUploadpath();
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        List<DealerAttachment> result = dealerAttachmentService.selectByDid(did);
        return  new SimpleCoreResponse("200","修改成功",result);
    }
}

